// summary:
//   Utility ANVIL functions that utilize YUI.
//   This file depends on "anvil.js" 

if (typeof ANVIL == "undefined") {
    throw { name: "error",
            message: "The dependency ANVIL is undefined." };
    }

ANVIL.yui = {};

ANVIL.yui.async = function (url, request, callback) {
    return YAHOO.util.Connect.asyncRequest("POST", url,
    {
        success : function(o)
        {
            if (typeof(callback) !== "function")
                return;
             var payload =  eval("(" + o.responseText + ")") ; // JSON.eval(o.responseText)           
             if (payload.error) {
                ANVIL.error( payload.error.message, payload.error.stackTrack );
                 return;
              }
            callback(payload);
        },

        failure : function(o)
        {
            ANVIL.channelError(o.responseText);
        }
    },
    "JSON-RPC=" + encodeURIComponent(JSON.stringify(request)));
};

ANVIL.yui.channel = function (fnCaller) {
    return ANVIL.yui.async(fnCaller.url, fnCaller.request, fnCaller.callback);
};

ANVIL.yui.onClear = function (p_oEvent) {
    if (ANVIL.isMessage()) { 
        ANVIL.clearMessage(); 
    }
};
